package brainsplash.gyrusscope.game;

import brainsplash.gyrusscope.framework.gl.TextureRegion;
import android.graphics.Bitmap;
import android.util.Log;

public class Enemy extends Spaceship{
	public float[][] path = null;
	public int destinationIndex = 1;
	public float hold = 0;
	public float offset = 0;
	public boolean canAttack = false;
	
	public Enemy(TextureRegion sprite, int x, int y, int radius, float distanceFromCenter, float direction, float speed) {
		super(sprite, x, y, radius, distanceFromCenter, direction, speed);
	}
	
	public Enemy(TextureRegion sprite, int x, int y, int radius, float[][] wavePaths, float offset) {
		super(sprite, x, y, radius, wavePaths[0][0], wavePaths[0][1], wavePaths[0][2]);
		path = wavePaths;
		this.offset = offset;
		direction += offset;
	}
	
	public void update() {
		if (path == null) {direction += 2;}
		else {
			float targetDistFromCenter = path[destinationIndex][0];
			float targetDirection = path[destinationIndex][1] + offset;
			float targetSpeed = path[destinationIndex][2] + (Level.waveCounter / 25);
			float targetHold = path[destinationIndex][3];
			
			direction += (float) (Math.signum(Math.min(direction - targetDirection,
					targetDirection - direction))) * targetSpeed * (distanceFromCenter / 100);
			if (distanceFromCenter <= 15) {direction += 0.05;}
			if ((Math.abs(distanceFromCenter - targetDistFromCenter) > targetSpeed) && hold == 0) {
				speed = Math.signum(distanceFromCenter - targetDistFromCenter) * targetSpeed;
			}
			else {
				hold += 1;
				speed = 0;
				
				if (hold >= targetHold) {
					hold = 0;
					destinationIndex += 1; 
					destinationIndex %= path.length;
					if (destinationIndex == 0) {canAttack = true;}
				}
			}
		}
		super.update();
	}
}
